Skip to content

Fix/referrers filters applied - #325

Open
sjalloq wants to merge 2 commits into
oras-project:mainfrom
sjalloq:fix/referrers-filters-applied
Open

sjalloq wants to merge 2 commits into
oras-project:mainfrom
sjalloq:fix/referrers-filters-applied

Conversation

@sjalloq

@sjalloq sjalloq commented Nov 12, 2026

Copy link
Copy Markdown

Fixes #318.

What changes

When pull_referrers is given an artifact type and the registry supports the referrers API, the client now filters the response itself unless the registry reports that it applied the filter. Before, it returned whatever the registry sent, so a registry that ignores artifactType returned referrers of every type.

The registry's report is read from two places:

  • The OCI-Filters-Applied response header. The value is a comma-separated list, and an entry must equal artifactType exactly.
  • The index annotation org.opencontainers.referrers.filtersApplied. Version 1.1.0-rc1 of the spec used it before the header existed.

There is no public API change.

Why it is done this way

  • The spec allows a registry to ignore the filter. Filtering is a SHOULD, and the header is how a client can tell whether it happened.
  • The logic is a copy of oras-go. See referrersPageByAPI and isReferrersFilterApplied. That is where the annotation and the exact matching come from.
  • The tag-schema fallback is not touched. The issue proposed a helper shared by both paths. The fallback already filters correctly, so leaving it alone keeps the change to the one path that was wrong.

How behaviour differs from main

  • Registry reports the filter: no change. The response is returned as it is.
  • Registry ignores the filter: the caller now gets only the referrers of the requested type.
  • Registry filters but does not report it: the client filters again, with the same result.
  • No artifact type requested: no change.

Two differences from oras-go remain:

Tests

The first commit adds four tests in tests/referrers_filters_applied.rs, against a fake registry that never filters. Two fail on main and are ignored: the registry reports nothing, and the registry reports a different filter. Two pass and guard that the header and the annotation are trusted. The second commit is the fix and enables the ignored tests.

To see the failures: cargo test --test referrers_filters_applied -- --include-ignored on the first commit.

A registry may ignore the `artifactType` filter of the referrers API. It
reports a filter that it applied in the `OCI-Filters-Applied` header.
`pull_referrers` does not read the header and does not filter the
response, so the caller gets every referrer.

The first two tests describe the expected behaviour. They are ignored
because they fail until the fix in the next commit. The other two tests
pass already: they show that the response of a registry which reports
the filter is returned as it is.

Refs: oras-project#318
Signed-off-by: Shareef Jalloq <shareef@jalloq.co.uk>
A registry may ignore the `artifactType` filter of the referrers API. It
reports a filter that it applied in the `OCI-Filters-Applied` header.
`pull_referrers` did not read the header and did not filter the
response, so the caller got every referrer from such a registry.

`pull_referrers` now filters the response itself, unless the registry
reports that it applied the filter. This follows `referrersPageByAPI` in
oras-go: the report is read from the header, or from the index
annotation `org.opencontainers.referrers.filtersApplied` that version
1.1.0-rc1 of the distribution specification used. An entry of the list
must be equal to `artifactType`.

Fixes: oras-project#318
Signed-off-by: Shareef Jalloq <shareef@jalloq.co.uk>
@sjalloq
sjalloq force-pushed the fix/referrers-filters-applied branch from 35af0d4 to a61f302 Compare November 28, 2026 08:40
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

pull_referrers doesn't filter by artifactType when the registry ignores the filter

1 participant